package com.sakura.mall.coupon.seckillSkuNotice.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.coupon.seckillSkuNotice.domain.request.AddSeckillSkuNoticeRequest;
import com.sakura.mall.coupon.seckillSkuNotice.domain.request.UpdateSeckillSkuNoticeRequest;
import com.sakura.mall.coupon.seckillSkuNotice.domain.request.SeckillSkuNoticePageRequest;
import com.sakura.mall.coupon.seckillSkuNotice.service.SeckillSkuNoticeService;
import com.sakura.mall.coupon.seckillSkuNotice.domain.vo.SeckillSkuNoticeVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀商品通知订阅
 *
 * @author sakura
 */
@RestController
@RequestMapping("/seckillSkuNotice")
@RequiredArgsConstructor
public class SeckillSkuNoticeController {

    private final SeckillSkuNoticeService seckillSkuNoticeService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddSeckillSkuNoticeRequest request) {
        seckillSkuNoticeService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<SeckillSkuNoticeVo>}
     */
    @GetMapping("list")
    public R<Page<SeckillSkuNoticeVo>> page(SeckillSkuNoticePageRequest request) {
        Page<SeckillSkuNoticeVo> ret = seckillSkuNoticeService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        seckillSkuNoticeService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateSeckillSkuNoticeRequest request) {
        seckillSkuNoticeService.updateById(id, request);
        return R.ok();
    }

}
